package com.henry.chatkit

import android.content.Context
import androidx.fragment.app.FragmentActivity
import com.blankj.utilcode.constant.PermissionConstants
import com.blankj.utilcode.util.FileUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.PermissionUtils
import com.blankj.utilcode.util.ToastUtils
import com.henry.chatkit.utils.BackgroundTasks

class ChatKit private constructor() {
    companion object {
        val instance: ChatKit by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            ChatKit() }
    }

    lateinit var context: Context
    lateinit var activity: FragmentActivity

    fun initKit(context: Context) {
        this.context = context
        if (context is FragmentActivity) {
            activity = context
        }
        BackgroundTasks.initInstance()

        initPath()

        // 权限
        PermissionUtils.permission(
            PermissionConstants.STORAGE,
            PermissionConstants.CAMERA,
            PermissionConstants.MICROPHONE
        )
            .callback(object : PermissionUtils.SimpleCallback {
                override fun onGranted() {
                    LogUtils.d("权限已申请")
                }

                override fun onDenied() {
                    ToastUtils.showLong("权限被拒绝，相关功能无法使用，需手动设置开启权限")
                }

            })
    }

    private fun initPath() {
        FileUtils.createOrExistsDir(Constants.VOICE_DIR)
        FileUtils.createOrExistsDir(Constants.IMAGE_BASE_DIR)
        FileUtils.createOrExistsDir(Constants.IMAGE_HEAD_DIR)
    }


    fun showView(context: FragmentActivity) {

    }

}